package com.hxc.shop.controller;

import com.hxc.shop.common.ResultVO;
import com.hxc.shop.service.MainImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/mainImage")
@CrossOrigin
@Api(tags = {"首页轮播图"})
public class MainImageController {
    @Resource
    private MainImageService mainImageService;

    @ApiOperation("获取所有首页轮播图")
    @GetMapping("/getAllMainImage")
    public ResultVO getAllMainImage(){
        return mainImageService.getAllMainImage();
    }

    @ApiOperation("获取首页轮播图,随机获取5个")
    @GetMapping("/getMainImage")
    public ResultVO getMainImage(){
        return mainImageService.getMainImage();
    }

    @ApiOperation("随机获取x个首页轮播图")
    @GetMapping("/getMainImageByCount")
    @ApiImplicitParams({
            @ApiImplicitParam(name="count",value = "首页轮播图数量",required = true,paramType = "Integer"),
    })
    public ResultVO getMainImage(@RequestParam("count")Integer count){
        return mainImageService.getMainImageByCount(count);
    }

    @ApiOperation("插入首页轮播图数据")
    @GetMapping("insertMainImage")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mainImage",value = "首页轮播图图片路径",required = true,paramType = "string"),
    })
    public ResultVO insertMainImage(String mainImage) {
        return mainImageService.insertMainImage(mainImage);
    }

    @ApiOperation("修改首页轮播图")
    @GetMapping("updateMainImage")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "首页轮播图编号",required = true,paramType = "Integer"),
            @ApiImplicitParam(name="mainImage",value = "首页轮播图图片路径",required = true,paramType = "string"),
    })
    public ResultVO updateMainImage(@RequestParam("id")Integer id,@RequestParam("mainImage")String mainImage) {
        return mainImageService.updateMainImage(id,mainImage);
    }

    @ApiOperation("删除首页轮播图")
    @GetMapping("deleteMainImage")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "首页轮播图编号",required = true,paramType = "Integer"),
    })
    public ResultVO deleteMainImage(@RequestParam("id")Integer id) {
        return mainImageService.deleteMainImage(id);
    }

    @ApiOperation("根据轮播图id获取首页轮播图数据")
    @GetMapping("/getMainImageById")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "首页轮播图编号",required = true,paramType = "Integer"),
    })
    public ResultVO getMainImageById(@RequestParam("id")Integer id){
        return mainImageService.getMainImageById(id);
    }










}
